﻿package com.amcharts.utils
{
    import flash.events.*;
    import flash.utils.*;

    public class Tween extends Object
    {
        private var _start:Number;
        private var _interval:Number;
        private var _eventDispatcher:EventDispatcher;
        private var _stepCount:Number;
        private var _frame_rate:Number = 25;
        private var _step:Number = 0;
        private var _duration:Number;
        private var _property:String;
        private var _effect:Function;
        private var _obj:Object;
        private var _end:Number;
        static const VERSION:String = "1.8.3.1";

        public function Tween(param1:ExtendedSprite, param2:String, param3:Function, param4:Number, param5:Number, param6:Number)
        {
            _obj = param1;
            _property = param2;
            _effect = param3;
            _start = param4;
            _end = param5;
            _eventDispatcher = new EventDispatcher();
            _duration = param6;
            _stepCount = Math.floor(_duration * _frame_rate);
            _step = 0;
            if (_obj.tweens[param2])
            {
                _obj.tweens[param2].stop();
                _obj.tweens[param2] = null;
            }
            _obj[_property] = _start;
            changeProperty();
            _interval = setInterval(changeProperty, 1000 / _frame_rate);
            return;
        }// end function

        private function changeProperty() : void
        {
            _obj[_property] = _effect(_step, _start, _end - _start, _stepCount);
            var _loc_2:* = _step + 1;
            _step = _loc_2;
            if (_step >= _stepCount)
            {
                _obj[_property] = _end;
                clearInterval(_interval);
                _eventDispatcher.dispatchEvent(new Event("onMotionFinished"));
            }
            return;
        }// end function

        public function stop() : void
        {
            clearInterval(_interval);
            return;
        }// end function

    }
}
